


<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js" lang="en">
<!--<![endif]-->

<head>
  <meta charset="utf-8">
  <meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />

  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>环境配置 &mdash; HAI Platform  documentation</title>
  

  <link rel="shortcut icon" href="../_static/images/logo192.png" />
  
  

  

  
  
  

  

  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <!-- <link rel="stylesheet" href="../_static/pygments.css" type="text/css" /> -->
  <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/custom.css" type="text/css" />
  <link rel="stylesheet" href="../_static/css/element-plus.css" type="text/css" />
  <link rel="index" title="Index" href="../genindex.html" />
  <link rel="search" title="Search" href="../search.html" />
  <link rel="next" title="分时调度" href="schedule.html" />
  <link rel="prev" title="命令行工具 (CLI)" href="tutorial.html" />
  <!-- Google Analytics -->
  <script type="text/javascript">
    var collapsedSections = [];
  </script>
  
  <!-- End Google Analytics -->
  

  
  <script src="../_static/js/modernizr.min.js"></script>
  <script>
    MathJax = {
        chtml: {
            scale: 1,
            minScale: 1,
        },
        svg: {
            scale: 1,
            minScale: 1,
        }
    }
</script>

  <!-- Preload the theme fonts -->

<link rel="preload" href="../_static/fonts/FreightSans/freight-sans-book.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/FreightSans/freight-sans-medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/IBMPlexMono/IBMPlexMono-Medium.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/FreightSans/freight-sans-bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/FreightSans/freight-sans-medium-italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/fonts/IBMPlexMono/IBMPlexMono-SemiBold.woff2" as="font" type="font/woff2" crossorigin="anonymous">

<!-- Preload the katex fonts -->

<link rel="preload" href="../_static/external/KaTeX_Math-Italic.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/external/KaTeX_Main-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/external/KaTeX_Main-Bold.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/external/KaTeX_Size1-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/external/KaTeX_Size4-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/external/KaTeX_Size2-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/external/KaTeX_Size3-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
<link rel="preload" href="../_static/external/KaTeX_Caligraphic-Regular.woff2" as="font" type="font/woff2" crossorigin="anonymous">
  <link rel="stylesheet" href="../_static/external/all.css"
    integrity="sha384-vSIIfh2YWi9wW0r9iZe7RJPrKwp6bG+s9QZMoITbCckVJqGCCRhc+ccxNcdpHuYu" crossorigin="anonymous">
</head>

<div class="container-fluid header-holder tutorials-header" id="header-holder">
  <div class="container">
    <div class="header-container">
      <a class="header-logo" href=""
        aria-label="OpenMMLab"></a>

      <div class="main-menu">
        <ul>
        </ul>
      </div>

      <!-- <a class="main-menu-open-button" href="#" data-behavior="open-mobile-menu"></a> -->
    </div>
  </div>
</div>

<body class="pytorch-body">

   

  

  <div class="table-of-contents-link-wrapper">
    <span>Table of Contents</span>
    <a href="#" class="toggle-table-of-contents" data-behavior="toggle-table-of-contents"></a>
  </div>

  <nav data-toggle="wy-nav-shift" class="pytorch-left-menu" id="pytorch-left-menu">
    <div class="pytorch-side-scroll">
      <div class="pytorch-menu pytorch-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
        <div class="pytorch-left-menu-search">
          

          
          
          
          

          



<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search Docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        
        
        
        
        
        <p class="caption" role="heading"><span class="caption-text">开始使用</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../start/hai_intro.html">基本介绍</a></li>
<li class="toctree-l1"><a class="reference internal" href="../start/install.html">安装与设置</a></li>
<li class="toctree-l1"><a class="reference internal" href="../start/studio.html">Studio</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">用户须知</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="tutorial.html">命令行工具 (CLI)</a></li>
<li class="toctree-l1 current"><a class="current reference internal" href="#">环境配置</a></li>
<li class="toctree-l1"><a class="reference internal" href="schedule.html">分时调度</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">CLI 说明</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../cli/user.html">用户命令</a></li>
<li class="toctree-l1"><a class="reference internal" href="../cli/exec.html">运行命令</a></li>
<li class="toctree-l1"><a class="reference internal" href="../cli/task.html">任务命令</a></li>
<li class="toctree-l1"><a class="reference internal" href="../cli/cluster.html">集群命令</a></li>
<li class="toctree-l1"><a class="reference internal" href="../cli/ugc.html">UGC 命令</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">API 说明</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../api/hai.html">hfai</a></li>
<li class="toctree-l1"><a class="reference internal" href="../api/client.html">hfai.client</a></li>
<li class="toctree-l1"><a class="reference internal" href="../api/client_remote.html">hfai.client.remote</a></li>
</ul>
<p class="caption" role="heading"><span class="caption-text">其他</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../misc/env_var.html">环境变量</a></li>
<li class="toctree-l1"><a class="reference internal" href="../misc/resources.html">外部资源</a></li>
</ul>

        
        
      </div>
    </div>
  </nav>

  <div class="pytorch-container">
    <div class="pytorch-page-level-bar" id="pytorch-page-level-bar">
      <div class="pytorch-breadcrumbs-wrapper">
        















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="pytorch-breadcrumbs">
    
      <li>
        <a href="../index.html">
            Docs
        </a> &gt;
      </li>

        
      <li>环境配置</li>
    
    
      <li class="pytorch-breadcrumbs-aside">
        
            
            <a href="../_sources/guide/environment.md.txt" rel="nofollow"><img src="../_static/images/view-page-source-icon.svg"></a>
          
        
      </li>
    
  </ul>

  
</div>
      </div>

      <div class="pytorch-shortcuts-wrapper" id="pytorch-shortcuts-wrapper">
        Shortcuts
      </div>
    </div>

    <section data-toggle="wy-nav-shift" id="pytorch-content-wrap" class="pytorch-content-wrap">
      <div class="pytorch-content-left">
        
          <div class="rst-content">
            
            <div role="main" class="main-content" itemscope="itemscope" itemtype="http://schema.org/Article">
              <article itemprop="articleBody" id="pytorch-article" class="pytorch-article">
                
  <section class="tex2jax_ignore mathjax_ignore" id="id1">
<h1>环境配置<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h1>
<p>运行环境是用户前期使用集群最关注的问题之一。 HAI Platform 提供两种方式配置环境：</p>
<ul class="simple">
<li><p>使用 <code class="docutils literal notranslate"><span class="pre">haienv</span></code> 调用 HAI Platform 默认环境（默认环境由集群提供）</p></li>
<li><p>使用 <code class="docutils literal notranslate"><span class="pre">haienv</span></code> 自建虚拟环境</p></li>
</ul>
<p>这两种方式的区别如下：</p>
<table class="colwidths-auto docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p></p></th>
<th class="head"><p>默认环境</p></th>
<th class="head"><p>自建环境</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>使用方式</p></td>
<td><p>提交任务时指定默认环境</p></td>
<td><p>开发容器中用 <code class="docutils literal notranslate"><span class="pre">haienv</span> <span class="pre">create</span></code> 命令创建环境，提交任务时指定自建环境</p></td>
</tr>
<tr class="row-odd"><td><p>是否支持自定义</p></td>
<td><p>不支持</p></td>
<td><p>支持扩展基础环境，或自定义虚拟环境</p></td>
</tr>
<tr class="row-even"><td><p>是否支持本地（集群外）使用</p></td>
<td><p>不支持</p></td>
<td><p>仅当本地环境与 HAI Platform 集群环境匹配时可使用，包括系统、GPU驱动、CUDA版本等</p></td>
</tr>
</tbody>
</table>
<section id="haienv">
<h2>使用 haienv 调用集群默认环境<a class="headerlink" href="#haienv" title="Permalink to this headline">¶</a></h2>
<p>在集群提供基础环境并包含大部分主流依赖包的情况下，用户有如下使用方式：
（<strong>建议用户在开始使用时先测试该环境是否可以满足运行需求</strong>）</p>
<ol class="arabic">
<li><p>不做代码更改，在使用 <a class="reference external" href="../cli/exec.html#hai-cli-python"><code class="docutils literal notranslate"><span class="pre">hai-cli</span> <span class="pre">python</span></code></a>, <a class="reference external" href="../cli/exec.html#hai-cli-bash"><code class="docutils literal notranslate"><span class="pre">hai-cli</span> <span class="pre">bash</span></code></a> 或 <a class="reference external" href="../cli/exec.html#hai-cli-exec"><code class="docutils literal notranslate"><span class="pre">hai-cli</span> <span class="pre">exec</span></code></a> 提交任务时，命令行中指定运行环境：</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="nv">HF_ENV_NAME</span><span class="o">=</span>&lt;<span class="w"> </span>base_env_name<span class="w"> </span>&gt;<span class="w"> </span>hai-cli<span class="w"> </span>python<span class="w"> </span>sample.py<span class="w"> </span>--<span class="w"> </span>-n<span class="w"> </span><span class="m">1</span><span class="w"> </span>--name<span class="w"> </span>test_exp_1
<span class="nv">HF_ENV_NAME</span><span class="o">=</span>&lt;<span class="w"> </span>base_env_name<span class="w"> </span>&gt;<span class="w"> </span>hai-cli<span class="w"> </span>bash<span class="w"> </span>sample.sh<span class="w"> </span>--<span class="w"> </span>-n<span class="w"> </span><span class="m">1</span><span class="w"> </span>--name<span class="w"> </span>test_exp_1
<span class="nv">HF_ENV_NAME</span><span class="o">=</span>&lt;<span class="w"> </span>base_env_name<span class="w"> </span>&gt;<span class="w"> </span>hai-cli<span class="w"> </span><span class="nb">exec</span><span class="w"> </span>mybin<span class="w"> </span>--<span class="w"> </span>-n<span class="w"> </span><span class="m">1</span><span class="w"> </span>--name<span class="w"> </span>test_exp_1
</pre></div>
</div>
</li>
<li><p>在运行python代码中，使用 <code class="docutils literal notranslate"><span class="pre">haienv</span></code> 加载运行环境：</p>
<div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">import</span> <span class="nn">haienv</span>
<span class="n">haienv</span><span class="o">.</span><span class="n">set_env</span><span class="p">(</span><span class="s1">&#39;env_name&#39;</span><span class="p">)</span>
</pre></div>
</div>
</li>
<li><p>在运行shell代码中，使用 <code class="docutils literal notranslate"><span class="pre">source</span></code> 命令加载运行环境：</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span><span class="nb">source</span><span class="w"> </span>haienv<span class="w"> </span>&lt;<span class="w"> </span>base_env_name<span class="w"> </span>&gt;
</pre></div>
</div>
</li>
</ol>
</section>
<section id="id2">
<h2>使用 haienv 自建虚拟环境<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h2>
<p>在基础环境无法满足用户需求的情况下（比如python版本、依赖包等），用户使用 <code class="docutils literal notranslate"><span class="pre">haienv</span></code> 工具创建和管理个人环境。</p>
<p>通常建议用户直接从集群基础环境中扩展配置个人环境。这种方式是<strong>增量</strong>的，<strong>仅需要安装集群默认环境里缺少的依赖即可</strong>。扩展配置环境需要在<strong>开发容器</strong>中操作，开发容器从 <a class="reference internal" href="../start/studio.html"><span class="doc std std-doc">Studio</span></a> 功能入口进入，如下图所示：</p>
<p><img alt="" src="../_images/devcontainer_01.png" /></p>
<p>HAI Platform 提供两种资源模式的开发容器</p>
<table class="colwidths-auto docutils align-default">
<thead>
<tr class="row-odd"><th class="head"><p></p></th>
<th class="head"><p>mig-gpu 开发容器</p></th>
<th class="head"><p>spot 开发容器</p></th>
</tr>
</thead>
<tbody>
<tr class="row-even"><td><p>创建入口</p></td>
<td><p><img alt="" src="../_images/devcontainer_02.png" /></p></td>
<td><p><img alt="" src="../_images/devcontainer_03.png" /></p></td>
</tr>
<tr class="row-odd"><td><p>资源分配</p></td>
<td><p>多个用户容器共享节点，每个容器绑定一个mig切分GPU</p></td>
<td><p>每个容器独占一个节点（8卡）</p></td>
</tr>
<tr class="row-even"><td><p>生命时长</p></td>
<td><p>默认24小时，活跃期间随时可续</p></td>
<td><p>无固定时长，根据集群资源需求随时回收</p></td>
</tr>
<tr class="row-odd"><td><p>启动条件</p></td>
<td><p>用户配额内随时可启动</p></td>
<td><p>根据集群资源需求动态开放</p></td>
</tr>
</tbody>
</table>
<p><strong>注意</strong>：这种操作无法将配置好的环境拉取到本地，代码无法在本地进行测试调优。如果您需要 Debug 代码，可以在开发容器中执行。</p>
<p><strong>具体的使用方式如下：</strong></p>
<p>首先进入开发容器命令行，通过如下命令创建用户环境：</p>
<div class="highlight-shell notranslate"><div class="highlight"><pre><span></span>haienv<span class="w"> </span>create<span class="w"> </span>&lt;<span class="w"> </span>myenv<span class="w"> </span>&gt;
</pre></div>
</div>
<p>注意不加 <code class="docutils literal notranslate"><span class="pre">--no_extend</span></code> 命令表示从 HAI Platform 默认环境扩展构建用户环境，最大降低环境配置的工作量。环境创建后即可进入环境并执行自定义安装。</p>
<p>除此以外，<code class="docutils literal notranslate"><span class="pre">haienv</span></code> 支持用户在本地（集群外）建立个人环境并推送到集群，这种方式建立的环境无法扩展基础环境，需要用户自己验证和维护。</p>
<p>自建环境与集群默认环境使用方式相同，支持提交任务指定和代码中加载。</p>
</section>
</section>


              </article>
              
            </div>
            <footer>
  
  <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
    
    <a href="schedule.html" class="btn btn-neutral float-right" title="分时调度" accesskey="n"
      rel="next">Next <img src="../_static/images/chevron-right-blue.svg"
        class="next-page"></a>
    
    
    <a href="tutorial.html" class="btn btn-neutral" title="命令行工具 (CLI)" accesskey="p"
      rel="prev"><img src="../_static/images/chevron-right-blue.svg" class="previous-page"> Previous</a>
    
  </div>
  

  <hr>

  <div role="contentinfo">
    <p>
      &copy; Copyright 2023, High-Flyer.

    </p>
  </div>
  
  <div>
    Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a
      href="https://github.com/rtfd/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the
      Docs</a>.
  </div>
   

</footer>
          </div>
        </div>

        <div class="pytorch-content-right" id="pytorch-content-right">
          <div class="pytorch-right-menu" id="pytorch-right-menu">
            <div class="pytorch-side-scroll" id="pytorch-side-scroll-right">
              <ul>
<li><a class="reference internal" href="#">环境配置</a><ul>
<li><a class="reference internal" href="#haienv">使用 haienv 调用集群默认环境</a></li>
<li><a class="reference internal" href="#id2">使用 haienv 自建虚拟环境</a></li>
</ul>
</li>
</ul>

            </div>
          </div>
        </div>
    </section>
  </div>

  


  

  
  <script type="text/javascript" id="documentation_options" data-url_root="../"
    src="../_static/documentation_options.js"></script>
  <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
  <script src="../_static/jquery.js"></script>
  <script src="../_static/underscore.js"></script>
  <script src="../_static/doctools.js"></script>
  <script src="../_static/js/vue.global.prod.js"></script>
  <script src="../_static/js/element-plus.full.js"></script>
  

  

  <script type="text/javascript" src="../_static/js/vendor/popper.min.js"></script>
  <script type="text/javascript" src="../_static/js/vendor/bootstrap.min.js"></script>
  <script src="../_static/external/list.min.js"></script>
  <script type="text/javascript" src="../_static/js/theme.js"></script>

  <script type="text/javascript">
    jQuery(function () {
      SphinxRtdTheme.Navigation.enable(true);
      });
  </script> 

  <!-- Begin Footer -->

  <!-- <div class="container-fluid docs-tutorials-resources" id="docs-tutorials-resources">
  </div> -->

  <!-- End Footer -->

  <!-- Begin Mobile Menu -->

  <div class="mobile-main-menu">
    <div class="container-fluid">
      <div class="container">
        <div class="mobile-main-menu-header-container">
          <a class="header-logo" href="" aria-label="OpenMMLab"></a>
          <a class="main-menu-close-button" href="#" data-behavior="close-mobile-menu"></a>
        </div>
      </div>
    </div>

    <div class="mobile-main-menu-links-container">
      <div class="main-menu">
        <ul>
      </div>
    </div>
  </div>

  <!-- End Mobile Menu -->

  <script type="text/javascript" src="../_static/js/vendor/anchor.min.js"></script>

  <script type="text/javascript">
    $(document).ready(function () {
      mobileMenu.bind();
      mobileTOC.bind();
      pytorchAnchors.bind();
      sideMenus.bind();
      scrollToAnchor.bind();
      highlightNavigation.bind();
      mainMenuDropdown.bind();
      filterTags.bind();

      // Add class to links that have code blocks, since we cannot create links in code blocks
      $("article.pytorch-article a span.pre").each(function (e) {
        $(this).closest("a").addClass("has-code");
      });
    })
  </script>
</body>

</html>